package com.wc.AlgoOJ_train.train3_算法大礼包.c1_广度优先搜索.AG0206_地牢大师;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Queue;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/1/27 17:46
 * @description http://43.138.190.70:8888/p/AG0206
 */
public class Main {
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 110;
    static char[][][] map = new char[N][N][];
    static int opLen = 6;
    static int[] posX = new int[]{-1, 1, 0, 0, 0, 0};
    static int[] posY = new int[]{0, 0, -1, 1, 0, 0};
    static int[] posZ = new int[]{0, 0, 0, 0, -1, 1};
    static int[][][] step = new int[N][N][N];
    static int x, y, z;
    static int sx, sy, sz;
    static int ex, ey, ez;
    static int n, m, l;

    public static void main(String[] args) {
        while (sc.hasNext()) {
            n = sc.nextInt();
            m = sc.nextInt();
            l = sc.nextInt();
            if (n == 0) {
                break;
            }

            for (int i = 1; i <= n; i++) {
                for (int j = 1; j <= m; j++) {
                    Arrays.fill(step[i][j], 0);
                    String s = " " + sc.next();
                    // 找到开头
                    int startZ = s.indexOf('S');
                    if (startZ != -1) {
                        sx = i;
                        sy = j;
                        sz = startZ;
                    }
                    // 找到结尾
                    int endZ = s.indexOf('E');
                    if (endZ != -1) {
                        ex = i;
                        ey = j;
                        ez = endZ;
                    }
                    map[i][j] = s.toCharArray();
                }
            }
            // 把结尾弄成路
            map[ex][ey][ez] = '.';

            int res = bfs();
            if (res == -1) {
                out.println("Trapped!");
            } else {
                out.printf("Escaped in %d minute(s).\n", res);
            }
        }
        out.flush();
    }

    static int bfs() {
        Queue<Integer> q = new LinkedList<>();
        q.add(sx);
        q.add(sy);
        q.add(sz);

        while (!q.isEmpty()) {
            x = q.poll();
            y = q.poll();
            z = q.poll();
            if (x == ex && y == ey && z == ez) {
                return step[x][y][z];
            }
            for (int i = 0; i < opLen; i++) {
                int nx = x + posX[i];
                int ny = y + posY[i];
                int nz = z + posZ[i];
                if (!isBorder(nx, ny, nz) && map[nx][ny][nz] == '.' && step[nx][ny][nz] == 0) {
                    step[nx][ny][nz] = step[x][y][z] + 1;
                    q.add(nx);
                    q.add(ny);
                    q.add(nz);
                }
            }
        }
        return -1;
    }

    static boolean isBorder(int x, int y, int z) {
        return x < 1 || x > n || y < 1 || y > m || z < 1 || z > l;
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}